﻿//DavidLee 2020/01/07
//对后台公用组件进行统一管理,避免每个页面重复编码
$(function () {
    'use strict';
    layui.use(['element', 'notice', 'layer', 'table'], function () {
        var layer = layui.layer,
            element = layui.element,
            table = layui.table,
            notice = Util.notice !== null && Util.notice() !== null
                ? Util.notice() : layui.notice;
        var openTips;
        $(document.body).on("mouseenter", ".toolgroup", function () {
            var tips = $(this).data('tips');
            openTips = layer.tips(tips, $(this), { tips: [2, '#2f4056'], time: 30000 });
        });
        $(document.body).on("mouseleave", ".toolgroup", function () {
            try {
                layer.close(openTips);
            } catch (e) {
                console.log(e.message);
            }
        });

        var toolgrp = {
            collaps: function () {
                var othis = this,
                    isShow = $(othis).attr('data-side-fold'),
                    widthelement = $(othis).attr("data-widthelement"),
                    leftelement = $(othis).attr("data-leftelement");
                if (isShow === "1") { // 缩放
                    $(othis).attr('data-side-fold', 0);
                    $("." + widthelement).animate({ width: 'toggle' }, "slow", function () {
                        $(othis).find("i").attr('class', 'fa fa-indent');
                        $(othis).data("tips", "展开侧边栏");
                        if ($("table").length > 0) table.resize();
                    });
                    $('.' + leftelement).animate({ left: 0 });
                } else { // 正常
                    $(othis).attr('data-side-fold', 1);
                    $('.' + leftelement).animate({ left: '220px' });
                    $("." + widthelement).animate({ width: 'toggle' }, "slow", function () {
                        $(othis).find("i").attr('class', 'fa fa-outdent');
                        $(othis).data("tips", "收起侧边栏");
                        if ($("table").length > 0) table.resize();
                    });
                }
                element.init();
            },
            expand: function (formName) {
                var othis = this;
                if ($(othis).hasClass("expand")) {
                    $("." + formName).show(300, function () {
                        $(othis).removeClass("expand").empty();
                        $(othis).append('收起搜索 <i class="layui-icon layui-icon-up"></i>');
                    });
                } else {
                    $("." + formName).hide(300, function () {
                        $(othis).addClass("expand").empty();
                        $(othis).append('展开搜索 <i class="layui-icon layui-icon-down"></i>');
                    });
                }
            }
        };
        $(document).delegate('.toolgroup', 'click', function (event) {
            var type = $(this).data('type');
            toolgrp[type] ? toolgrp[type].call(this) : '';
            event.stopPropagation();
        });

        //展开搜索框
        var $seachExpandBtn = $("a.form-search-expand");
        if ($seachExpandBtn.length > 0) {
            const formName = $seachExpandBtn.data("formclassname");
            if (formName !== null && formName !== undefined && formName !== "") {
                $("." + formName).hide();
                $(document).delegate("a.form-search-expand", 'click', function (event) {
                    var type = $(this).data('type');
                    toolgrp[type] ? toolgrp[type].call(this, formName) : '';
                    event.stopPropagation();
                });
            }
        }
    });//layui.use([
}); //$(function () {